﻿using Gp.Scripts.Core;
using Helpers;
using UnityEngine;

namespace Gp.Scripts.Core {
    public class GameStateWaitForInput : GameState {
        // private Player _player;
        protected override void OnStateEnter(GameState lastState) {
            // _player = CellGridModel.CurrentPlayer;
            // Global.Get<CharacterSystem>().
            // var playerUnit = ObjectHelper.PlayerCharacter.GetComponent<BaseUnit>();
            // this.SwitchState(new GameStateUnitPlay(playerUnit));
        }


        // protected override void OnUnitClicked(BaseUnit u) {
        //     // SwitchUnitSelect(C3el);
        // }
        public override void OnEntitySelectEvent(BaseEntity entity, SelectEventType eventType)
        {
            base.OnEntitySelectEvent(entity, eventType);
            
            if (eventType != SelectEventType.SELECT || entity is not BaseUnit unit) return;
            
            LogHelper.LogInfo(nameof(GameStateWaitForInput), "OnEntitySelect - " + unit.UnitName + "\n" + unit.Guid);
            // 当有单位被点击，且当前为该单位玩家回合，则切换至该单位
            if (unit.PlayerNumber != (int) UnitCampNumber.PLAYER) return;
            
            this.SwitchState(new GameStateUnitSelect(unit));
        }


        // protected void SwitchUnitSelect(BaseUnit unit) {
        //     // 当有单位被点击，且当前为该单位玩家回合，则切换至该单位
        //     if (unit.PlayerNumber != CellGridSystem.Instance.CurrentPlayer.PlayerNumber) return;
        //
        //     SwitchState(new CellGridStateUnitPlay(unit));
        // }
        

        // public override void OnCellClicked(Cell cell) {
        //     // 当cell 被点击时，如果cell上方有单位，则视为该单位被点击
        //     var unit = GetUnit(cell);
        //     
        //     if (unit == null) return;
        //     this.OnUnitClicked(unit);
        // }



        // private BaseUnit GetUnit(Cell cell) {
        //     // 当cell 被点击时，如果cell上方有单位，则视为该单位被点击
        //     if (cell is not AttachCell ac) return null;
        //     var unit = CellGridSystem.Instance.PlaceHolder.GetUnit(ac);
        //
        //     return unit;
        // }
    }
}